package cn.lingyangwl.agile.auth;

import cn.lingyangwl.agile.auth.model.entity.*;
import cn.lingyangwl.agile.auth.model.rqrs.*;
import cn.lingyangwl.agile.auth.model.rqrs.ldp.*;
import cn.lingyangwl.agile.auth.model.rqrs.third.*;
import cn.lingyangwl.agile.model.constants.*;
import cn.lingyangwl.agile.model.module.auth.*;
import cn.lingyangwl.framework.core.response.*;
import com.alibaba.cloud.nacos.NacosServiceAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shenguangyang
 */
@FeignClient(contextId = "authRemote", value = ServiceCodeCons.AUTH_SERVICE)
@ConditionalOnClass({FeignAutoConfiguration.class, NacosServiceAutoConfiguration.class})
public interface AuthRemote {

	/**
	 * 获取外部身份源
	 * @param clientId 客户端id
	 */
	@GetMapping("/extLdpConnect/listByClientId")
	Resp<List<ExtLdpConnectResp>> listLdpConnectByClientId(@RequestParam("clientId") String clientId);

	/**
	 * 删除日志
	 */
	@PostMapping(value = "/loginLog/deleteLogTask", headers = SecurityCons.HEADER_FROM_IN)
	Resp<Integer> deleteLoginLog(@RequestParam("endTime") String endTime);


	/**
	 * 获取当前授权用户
	 */
	@GetMapping("/auth/getLoginUser")
	Resp<LoginUser> getLoginUser();

	/**
	 * 获取当前授权用户
	 */
	@PostMapping("/auth/updateLocalUser")
	Resp<Boolean> updateLoginUser(@RequestBody LoginUser req);

	/**
	 * 删除指定用户的访问令牌
	 */
	@DeleteMapping("/auth/removeAccessTokenByUserId")
	Resp<Boolean> removeAccessTokenByUserId(@RequestParam("userId") Long userId);
	/**
	 * 删除指定用户的访问令牌
	 */
	@DeleteMapping("/auth/removeAccessTokenByUserIds")
	Resp<Boolean> removeAccessTokenByUserIds(@RequestParam("userIds") List<Long> userIds);


	@PostMapping("/captcha/delete")
	Resp<?> deleteCaptcha(@RequestParam("uuid") String uuid);

	@PostMapping("/captcha/check")
	Resp<Boolean> checkCaptcha(@RequestBody CaptchaCheckReq req);

	/**
	 * 通过clientId 查询客户端信息
	 * @param clientId 用户名
	 * @return R
	 */
	@GetMapping(value = "/authClientDetails/getByClientId", headers = SecurityCons.HEADER_FROM_IN)
	Resp<OAuth2Client> getByClientId(@RequestParam("clientId") String clientId);


	/**
	 * 更新用户授权信息
	 */
	@PostMapping(value = "/localUser/updateLocalUser", headers = SecurityCons.HEADER_FROM_IN)
	Resp<?> updateLocalUser(@RequestBody LocalUser req);

	/**
	 * 保存用户授权信息
	 */
	@PostMapping(value = "/localUser/save", headers = SecurityCons.HEADER_FROM_IN)
	Resp<Long> saveLocalUser(@RequestBody LocalUser rq);

	/**
	 * 删除用户授权信息
	 */
	@DeleteMapping(value = "/localUser/delete", headers = SecurityCons.HEADER_FROM_IN)
	Resp<?> deleteLocalUser(@RequestParam("userId") Long userId);

	@DeleteMapping(value = "/localUser/batchDelete", headers = SecurityCons.HEADER_FROM_IN)
	Resp<?> batchDeleteLocalUser(@RequestParam("tenantId") String tenantId, @RequestParam("userIds") List<Long> userIds);

	/**
	 * 批量更新用户授权信息
	 */
	@PostMapping(value = "/localUser/batchUpdateLocalUser", headers = SecurityCons.HEADER_FROM_IN)
	Resp<?> batchUpdateLocalUser(@RequestBody List<LocalUser> rqList);

	/**
	 * 更新用户授权信息
	 */
	@GetMapping(value = "/localUser/listAuth", headers = SecurityCons.HEADER_FROM_IN)
	Resp<List<LocalUser>> listAuth(@SpringQueryMap LocalUserListReq query);

	@GetMapping(value = "/localUser/get", headers = SecurityCons.HEADER_FROM_IN)
	Resp<LocalUser> getUser(@SpringQueryMap LocalUserGetReq rq);

	@GetMapping(value = "/localUser/getUserByUserId", headers = SecurityCons.HEADER_FROM_IN)
	Resp<LocalUser> getUserByUserId(@RequestParam("userId") Long userId);

	/**
	 * 注销账号
	 */
	@PostMapping(value = "/localUser/cancelAccount")
	Resp<?> cancelAccount(@RequestBody CancelAccountReq req);

	/**
	 * 通过角色id刷新客户端权限
	 */
	@PostMapping(value = "/oauth/client/refreshAuthorityByRoleIds")
	Resp<?> refreshClientAuthorityByRoleIds(@RequestParam("roleId") List<Long> roleIds, @RequestParam("roleDeleted") Boolean roleDeleted);

	/**
	 * 用户进行了扫码操作
	 */
	@PostMapping(value = "/thirdAuth/userScanQrcode", headers = SecurityCons.HEADER_FROM_IN)
	Resp<?> userScanQrcode(@RequestBody LoginQrcodeInfo req);
}
